/**
 * 
 */
package com.p2p.base.util;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

import com.p2p.base.constents.InnerAccountConsts;
import com.p2p.base.util.mail.JavaWebapi;
import com.p2p.base.util.mail.SendCloudMail;
import com.p2p.base.util.sms.SMSService;

/**
 * @author ruiqi
 *
 */
public class BasePropertyConfigurer extends PropertyPlaceholderConfigurer{

	private static Map<String, String> ctxPropertiesMap;  
	  
    @Override  
    protected void processProperties(ConfigurableListableBeanFactory beanFactory,  
            Properties props)throws BeansException {  
  
        super.processProperties(beanFactory, props);  
        //load properties to ctxPropertiesMap  
        ctxPropertiesMap = new HashMap<String, String>();  
        for (Object key : props.keySet()) {  
            String keyStr = key.toString();  
            String value = props.getProperty(keyStr);  
            ctxPropertiesMap.put(keyStr, value);  
        }  
        SMSService.init();
        SendCloudMail.init(ctxPropertiesMap);
        JavaWebapi.init(ctxPropertiesMap);
       // InnerAccountConsts.init(ctxPropertiesMap);
    }  
  
    //static method for accessing context properties  
    public static String getContextProperty(String name) {  
    	if(ctxPropertiesMap == null){
    		return null;
    	}
        return ctxPropertiesMap.get(name);  
    }  
    
    
}
